package io.renren.modules.jxgkphone.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Utils {
    public static Map<String, String> getDayInfo(String curDate, String BeginDate) {
        Map<String, String> map = new HashMap<String, String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date cur, begin;
        try {
            cur = sdf.parse(curDate);
            begin = sdf.parse(BeginDate);
        } catch (Exception e) {
            System.out.println("请输入yyyy-MM-dd格式日期");
            return map;
        }
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar1.setTime(cur);
        calendar2.setTime(begin);
        String year = "", term = "";
        long week = 0, day;
        if (calendar2.get(Calendar.MONTH) >= 8) {
            // System.out.println(2);
            term = "1";
            year = calendar1.get(Calendar.YEAR) + "-" + (calendar1.get(Calendar.YEAR) + 1);
            // System.out.println(year);
        } else {
            //System.out.println(1);
            term = "2";
            year = (calendar2.get(Calendar.YEAR) - 1) + "-" + (calendar1.get(Calendar.YEAR));
            // System.out.println(year);
        }

        week = ((cur.getTime() - begin.getTime()) / (1000 * 3600 * 24 * 7)) + 1;
        day = calendar1.get(Calendar.DAY_OF_WEEK);
        if (day == 1) {
            day = 7;
        } else {
            day--;
        }
        // System.out.println(week);
        //System.out.println(day);
        map.put("date", curDate);
        map.put("year", year);
        map.put("term", term);
        map.put("week", week + "");
        map.put("day", day + "");
        //System.out.println(sdf.format(new Date()));
        return map;

    }
}
